import { createRenderer } from "../runtime-core"
let render
function ensureRenderer () {
    return (
        // createRenderer(nodeOps) 的返回值是一个创建vue实例的方法
        render || (render = createRenderer(nodeOps))
    )
}

// 创建app的方法
export const createApp = (...args) => {
    return ensureRenderer().createApp(...args)
}

// 节点操作 可以通过充血 nodeOps 实现跨端
const nodeOps = {
    insert(child, parent, anchor) {
      parent.insertBefore(child, anchor || null)
    },
    remove(child) {
      const parent = child.parentNode
      if (parent) {
        parent.removeChild(child)
      }
    },
    createElement(type) {
      return document.createElement(type)
    },
    createText(text) {
      return document.createTextNode(text)
    },
    setText(node, text) {
      node.nodeValue = text
    },
    setElementText(el, text) {
      el.textContent = text
    },
    parentNode: node => node.parentNode,
    nextSibling: node => node.nextSibling,
    querySelector: selector => doc.querySelector(selector),
    setScopeId(el, id) {
      el.setAttribute(id, '')
    },
    patchProp
  }